function showImportantVehicleSearch() {
	window.location.href = "showImportantVehicleSearch.do";
}

function ajaxFindImportantVehicleSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxImportantVehicleSearchList.do",
		data : {
			plateNum : $("#plateNum").val(),
			plateTypeId : $("#licencePlateKind").val(),
			vehicleTypeId : $("#vehicleType").val(),
			ownername : $("#ownername").val(),
			effectiveStartTime : $("#effectiveStartTime").val(),
			effectiveEndTime : $("#effectiveEndTime").val(),
			importantVehicleAuditId : $("#auditstatus").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listImportantVehicleBox").html(msg);
		}
	});
}

function ajaxShowImportantVehicleEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowImportantVehicleEdit.do",
		data:{importantVehicleId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 1258,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveImportantVehicle(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxSaveImportantVehicle(objDialog) {
	importantVehicleValidate();
	if ($("#frmImportantVehicle").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveImportantVehicle.do",
				success: function (msg) {
					clearInput("#sltImportantVehicle");
					ajaxFindImportantVehicleSearchList();
					showMessageDialog("保存重点车","重点车信息保存成功。",null,dialogType.info);
				}
		};
		$("#frmImportantVehicle").ajaxSubmit(options);
	}
}

function ajaxShowImportantVehicleView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowImportantVehicleView.do",
		data:{importantVehicleId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 1300,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ 
				           {
				        	   text: "撤销",
				        	   click: function() {
				        		   ajaxRepealImportantVehicle(id);
				        	   }
				           },
				           {
				        	   text: "审核",
				        	   click: function() {
				        		   ajaxShowImportantVehicleAudit(id);
				        	   }
				           },
				           {
				        	   text : "关闭",
				        	   click : function() {
				        		   $(this).dialog("close");
				        	   }
				           } ]
			});
		}
	});
}

function ajaxDeleteImportantVehicleById(id) {
	var importantVehicleIds="";
	var sltIV = $("#listImportantVehicleList tbody input:checked").length;
	if(id==null){
		$("#listImportantVehicleList tbody input:checked").each(function(){ 
			importantVehicleIds += $(this).val()+";";
		});
		if(sltIV == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			importantVehicleIds=importantVehicleIds.substring(0, importantVehicleIds.length-1);
		}
	}else{
		importantVehicleIds=id;
		sltIV = 1;
	}
	if( importantVehicleIds!=null) {
		showMessageDialog("删除重点车","确定要删除所选“"+sltIV+"”条重点车记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteImportantVehicleByIds.do",
				data:{importantVehicleIds:importantVehicleIds},
				success:function(msg){
					ajaxFindImportantVehicleSearchList();
					showMessageDialog("提示","重点车辆信息删除成功。",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function ajaxRepealImportantVehicle(id,url) {
	showMessageDialog("撤销重点车","确定要撤销重点车吗？",
			function () {
		$.ajax({     
			type:"post",
			url:"ajaxRepealImportantVehicle.do",
			data:{importantVehicleId:id},
			success:function(msg){
				showMessageDialog("提示","重点车辆撤销成功。",null,dialogType.info);
			}
		});
	}
	,dialogType.warning);
}

function ajaxShowImportantVehicleAudit(id,url){
	$.ajax({
		type:"post",
		url:"ajaxShowImportantVehicleAudit.do",
		data:{importantVehicleId:id},
		success:function(msg){
			$("#dialog2").html(msg);
			$("#dialog2").dialog({
				autoOpen: true,
				width: 700,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  showMessageDialog("提示","重点车辆审核信息保存成功。",null,dialogType.info);
				        		  $(this).dialog( "close" );
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

//导入
function ajaxImportImportantVehicle(id) {
	showMessageDialog("提示","导入数据成功",null,dialogType.info);
}
//导出
function ajaxExportImportantVehicle(id) {
	showMessageDialog("提示","导出数据成功",null,dialogType.info);
}

function importantVehicleValidate(){
	$("#frmImportantVehicle").validate({
		errorLabelContainer: $("#infoImportantVehicle"),
		rules : {
			"plateNum" : {
				required :true				
			},
			"plateTypeId" : {
				required :true				
			},
			effectiveStartTime : {
				required :true				
			},
			effectiveEndTime : {
				required :true				
			},
			cause : {
				required :true				
			},
			contact1 : {
				required :true				
			},
			contactWay1 : {
				required :true
			}
		},
		messages : {
			"plateNum": {
				required :"请输入号牌号码！"
			},
			"plateTypeId" : {
				required :"请输入号牌种类！"
			},
			effectiveStartTime : {
				required :"请输入初始日期！"
			},
			effectiveEndTime : {
				required :"请输入结束日期！"
			},
			cause : {
				required :"请输入增加原因！"
			},
			contact1 : {
				required :"请输入联系人！"
			},
			contactWay1 : {
				required :"请输入联系方式！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}